Adding some strings and geometry algorithms to notebook.
[andmenj-acm.git] / Mi manual de algoritmos / version_actual / src / geometria / is_inside_convex_polygon.cpp
bloba5adb9d10e9473899507c57c2a5254efa36839ae
1 /*
2 Returns true if point a is inside convex polygon p. Note
3 that if point a lies on the border of p it is considered
4 outside.
6 We assume p is convex! The result is useless if p is
7 concave.
8 */
9 bool insideConvexPolygon(const vector<point> &p,
10 const point &a){
11 int mask = 0;
12 int n = p.size();
13 for (int i=0; i<n; ++i){
14 int j = (i+1)%n;
15 double z = turn(p[i], p[j], a);
16 if (z < 0.0){
17 mask |= 1;
18 }else if (z > 0.0){
19 mask |= 2;
20 }else if (z == 0.0) return false;
21 if (mask == 3) return false;
23 return mask != 0;